/*--------------------劳务模块.工种管理--ly-----------------*/
/*--------------------工种新增功能  lb_job_add.html------------------*/

layui.use(['form', 'layer'], function() {
	$ = layui.jquery;
	var form = layui.form,
		layer = layui.layer;

	//自定义验证规则
	form.verify({
		jobname: function(value) {
			if(value.length < 3) {
				return '昵称至少得5个字符啊';
			}
		},
	
	});

	console.log("表单结果" + $('#lbjobadd').serialize());
	var url = laborport + "/LabourJobController/insert"; //请求数据url
	//post请求
	var postResult = (function() {
		$.post(url, $('#lbjobadd').serialize(), function(result) {
			console.log("结果" + JSON.stringify(result));
			if(result.code == '0') {
				layer.alert("增加成功", {
					icon: 6
				}, function() {
					// 获得frame索引
					var index = parent.layer.getFrameIndex(window.name);
					//关闭当前frame
					parent.layer.close(index);
				});
			} else {
				layer.alert("服务器繁忙，稍后再试", {
					icon: 5
				}, function() {
					// 获得frame索引
					var index = parent.layer.getFrameIndex(window.name);
					//关闭当前frame
					parent.layer.close(index);
				});
			}
		});
	})

	//监听提交
	form.on('submit(add)', function(data) {
		console.log(data);
		//发异步，把数据提交给php
		postResult();
		return false;
	});
});